package com.swufe.ccb.dao;


import java.sql.SQLException;

import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.swufe.ccb.entity.AffairHandle;
import com.swufe.ccb.utils.DbUtils;

public class AffairHandleDao {
	private QueryRunner runner = new QueryRunner( DbUtils.getDataSource() );
	
	public List<AffairHandle> findByAffair(){
		try {
			String sql = "select * from affair";
			//String sql_2 = "select * from affair where affairstatus=1";
			List<AffairHandle> list=runner.query(sql, new BeanListHandler<>(AffairHandle.class));
			//List<AffairHandle> list2=runner.query(sql_2, new BeanListHandler<>(AffairHandle.class));
			//System.out.print("Dao输出list"+list);
			return list;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	public AffairHandle findByAffairid( String affairid ) {
		try {
			String sql = "select * from affair where affairid=? ";
					
			return runner.query(sql, new BeanHandler<>(AffairHandle.class), affairid);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	public int update(AffairHandle affairid) {
			
			try {
				String sql = "UPDATE affair set affairstatus = 1 where affairid = ?";
				return runner.update(sql, affairid.getAffairstatus(),affairid.getAffairid());
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			return -1;
		}


}
